import {Cascader} from 'element-ui';
import { isEqual } from 'element-ui/lib/utils/util';
import { isUndefined } from 'element-ui/lib/utils/types';

// 重置
Cascader.watch.checkedValue = undefined;

export default {
  name: Cascader.name,
  mixins: [Cascader],
  watch: {
    checkedValue(val) {
      const { value, dropDownVisible } = this;
      const { checkStrictly, multiple } = this.config;

      if (!isEqual(val, value) || isUndefined(value)) {
        this.computePresentContent();
        // hide dropdown when single mode
        if (!multiple && !checkStrictly && dropDownVisible) {
          this.toggleDropDownVisible(false);
        }

        this.$emit('input', val);
        this.$emit('change', val);
        this.$nextTick(() => {
          this.dispatch('ElFormItem', 'el.form.change', [val]);
        });
      }
    },
  }
};
